package com.ui;

import javax.swing.*;
import java.awt.event.*;

public class ALL_pur_history extends JDialog {
    private JPanel contentPane;
    private JButton buttonOK;
    private JButton buttonCancel;
    private JTextField textField1;
    private JList list1;

    public ALL_pur_history() {
        setContentPane(contentPane);
        setModal(true);
        getRootPane().setDefaultButton(buttonOK);

        buttonOK.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onOK();
            }
        });

        buttonCancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        });

        // 点击 X 时调用 onCancel()
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                onCancel();
            }
        });

        // 遇到 ESCAPE 时调用 onCancel()
        contentPane.registerKeyboardAction(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    }

    private void onOK() {
        DENGLU.c.history.clear();
        DENGLU.c.usr.clear();
        for(int i=1;i<25;i++)
        {
            DENGLU.c.process(DENGLU.c.CheckHistory(i));
        }
        String[] lst=new String[DENGLU.c.history.size()+1];
        int i=1;
        lst[0]="单号        商品号        名称        数量        价格        用户";
        for(String key:DENGLU.c.history.keySet())
        {
            lst[i]=key+"        "+DENGLU.c.history.get(key).getID()+"        "+
                    DENGLU.c.history.get(key).getName()+"        "+
                    DENGLU.c.history.get(key).getNum()+"        "+
                    DENGLU.c.history.get(key).getPrice()+"        "+DENGLU.c.usr.get(i-1);
            i++;
        }


        list1.setListData(lst);


        //从textfield获得输入的字符串str进行查询，显示特定商品的购买记录，输入完只需按刷新按钮即可
        String str=textField1.getText();




    }

    private void onCancel() {
        // 必要时在此处添加您的代码
        dispose();
    }

    public void main() {
        ALL_pur_history dialog = new ALL_pur_history();
        dialog.pack();
        dialog.setVisible(true);
        //System.exit(0);
    }
}
